@echo off
echo [Info] Creating Release Package

set "foldername=sea-archiver"
:: 检查 sea-archiver 文件夹是否存在（不删也没关系,npm会动手）
if exist "%foldername%\" (
    rmdir /s /q "%foldername%"
    echo [Info] Old release folder <%foldername%> deleted.
) else (
    echo [Info] Folder "%foldername%" does not exist, skipping deletion.
)
mkdir ".\%foldername% "
:: 等待 npm 运行构建命令（vite.config.ts里已经写了build到.\sea-archiver\WebApp里）
echo [Info] Waiting for npm build...
call npm run build >nul

:: 复制文件到新的 SeaArchier 文件夹
echo [Info] Copying files to "%foldername%"... 

copy App_SeaArchiver.py ".\%foldername%" >nul
copy App_setting.py ".\%foldername%" >nul
xcopy App_preflight.py ".\%foldername%" >nul
xcopy service ".\%foldername%\service" /s /i >nul
xcopy WebBackend ".\%foldername%\WebBackend" /s /i >nul
xcopy version.json ".\%foldername%" >nul
:: 将文件CSRF换成LF
set "input_file=.\service\init.sh"
set "output_file=.\%foldername%\service\init.sh"
powershell -Command "(Get-Content '%input_file%' -Raw) -replace \"`r`n\", \"`n\" | Set-Content -NoNewline '%output_file%'"

echo [Info] Copying completed.
::npm build的时候WebApp已经过去了，不用复制